<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="合同编号" prop="vContractNo">
        <el-input
          v-model="queryParams.vContractNo"
          placeholder="请输入合同编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目编号" prop="vProjectNo">
        <el-input
          v-model="queryParams.vProjectNo"
          placeholder="请输入项目编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="零件名称" prop="vSpaName">
        <el-input
          v-model="queryParams.vSpaName"
          placeholder="请输入零件名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="规格型号" prop="vSpaModel">
        <el-input
          v-model="queryParams.vSpaModel"
          placeholder="请输入规格型号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="品牌" prop="vSpaBrand">
        <el-input
          v-model="queryParams.vSpaBrand"
          placeholder="请输入品牌"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="经办人" prop="oprBy">
        <el-input
          v-model="queryParams.oprBy"
          placeholder="请输入经办人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="入库时间">
        <el-date-picker
          v-model="daterangeArriveTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="ArriveInfoitemList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="合同编号" align="center" prop="vContractNo" />
      <el-table-column label="项目编号" align="center" prop="vProjectNo" />
      <el-table-column label="零件名称" align="center" prop="vSpaName" />
      <el-table-column label="规格型号" align="center" prop="vSpaModel" />
      <el-table-column label="品牌" align="center" prop="vSpaBrand" />
      <el-table-column label="经办人" align="center" prop="oprBy" />
      <el-table-column label="入库数量" align="center" prop="nQty" />
      <el-table-column label="入库时间" align="center" prop="arriveTime" />
      <el-table-column label="仓库" align="center" prop="vWHName" />
      <el-table-column label="库区" align="center" prop="vAreaName" />
      <el-table-column label="库位" align="center" prop="vLocationName" />
      <el-table-column label="备注" align="center" prop="remark" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { searchInList } from "@/api/inv/inv0011";

export default {
  name: "ArriveInfoitem",
  dicts: ["inv_arrival_status"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 到货单明细表格数据
      ArriveInfoitemList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 备注时间范围
      daterangeArriveTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        vContractNo: null,
        vProjectNo: null,
        vSpaName: null,
        vSpaModel: null,
        vSpaBrand: null,
        applyBy: null,
        oprBy: null,
        supplier: null,
        nDays: null,
        vArriveNo: null,
        nQty: null,
        createTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询到货单明细列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeArriveTime && "" != this.daterangeArriveTime) {
        this.queryParams.params["beginArriveTime"] =
          this.daterangeArriveTime[0];
        this.queryParams.params["beginArriveTime"] =
          this.daterangeArriveTime[1];
      }
      searchInList(this.queryParams).then((response) => {
        this.ArriveInfoitemList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        nMainId: null,
        status: null,
        vContractNo: null,
        vProjectNo: null,
        vSpaName: null,
        vSpaModel: null,
        vSpaBrand: null,
        applyBy: null,
        oprBy: null,
        supplier: null,
        nDays: null,
        vArriveNo: null,
        nQty: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeArriveTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加到货单明细";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getArriveInfoitem(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改到货单明细";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateArriveInfoitem(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addArriveInfoitem(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除到货单明细编号为"' + ids + '"的数据项？')
        .then(function () {
          return delArriveInfoitem(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/ArriveInfoitem/export",
        {
          ...this.queryParams,
        },
        `ArriveInfoitem_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
